<?php
class Model_DbTable_Article extends Apps_Db_Table_Abstract {
	protected $_name = 'article';

	const TYPE_NOMAL 	    = 1;
	const TYPE_ABOUT 	    = 2;
	const TYPE_SERVICE 	    = 3;
	const TYPE_CAREER 	    = 4;
	const TYPE_SYSTEM_SHOP 	= 5;


	const STATUS_ACTIVE   = 1;
	const STATUS_INACTIVE = 0;

	public function getList() {
		$q = $this->_db
				  ->select()
				  ->from($this->_name);

		return $q;
	}
	public function getArticleById($articleId) {
		return $this->_db
					->select()
					->from($this->_name)
					->where('article.id = ?', $articleId);
	}

	//delete article by reference id, type
	public function deleteArticleById($articleId) {
		$article = $this->getArticleById($articleId)->query()->fetch();
		if ($article) {
			if($this->safelyDelete(array('id  = ?' => $articleId))){
				unlink(Apps_Plugin_Upload_File::getPath($article['thumbnail']));
				return true;
			}
		}
	}

}